﻿using System;
using System.Diagnostics;
using System.Windows.Automation;
using System.Windows.Forms;

namespace XiaofangExamUIAutomation
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            AutomationElement root = AutomationElement.RootElement;
            PropertyCondition propertyCondition = new PropertyCondition(AutomationElement.NameProperty, "消防理论考试 - 山东盛恩技术人员技能考试 - Microsoft Edge");

            PropertyCondition pc2 = new PropertyCondition(AutomationElement.NameProperty, "消防理论考试 - 山东盛恩技术人员技能考试");
            PropertyCondition pc3 = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "文档");
            AutomationElement docmain = root.FindFirst(TreeScope.Descendants, new AndCondition(pc2, pc3));

            TreeWalker treeWalker = TreeWalker.RawViewWalker;
            var item = treeWalker.GetFirstChild(docmain);

            var item2 = treeWalker.GetFirstChild(item);

            var item3 = treeWalker.GetFirstChild(item2);
            var item4 = treeWalker.GetNextSibling(item3);
            var item5 = treeWalker.GetNextSibling(item4);
            var item6 = treeWalker.GetNextSibling(item5);
            var item7 = treeWalker.GetNextSibling(item6);

            var item8=treeWalker.GetFirstChild(item7);
            var item9 = treeWalker.GetFirstChild(item8);
            var item10 = treeWalker.GetFirstChild(item9);
            var item11 = treeWalker.GetFirstChild(item10);

            PropertyCondition pctigan = new PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "文本");

            var items = item11.FindAll(TreeScope.Children, pctigan);

            Debug.WriteLine(items[3].Current.Name);


        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Stop();
            //Debug.WriteLine("进入定时。。。。。。");
            //AutomationElement focus = AutomationElement.FocusedElement;
            //Debug.WriteLine(focus.Current.Name);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            //timer1.Start();
        }
    }
}
